// latency viewer

draw_interval = null;
simple_interval = null;

function resetTiming() {
  // re-set timers
  if (draw_interval)
    clearInterval(draw_interval);
  if (simple_interval)
    clearInterval(simple_interval);
  draw_interval = setInterval('draw()',document.getElementById('edtDrawInterval1').value);
  simple_interval = setInterval('simple()',document.getElementById('edtSimpleInterval1').value);  
}

function onLoad() {
  x = 320;
  y = 240;
  sprite = new Image();
  sprite.src = '../img/dummy/dummy0.png';
  canvas = document.getElementById('canvas');
	context = canvas.getContext('2d');
  resetTiming();
}

function draw() {
  // draw scene
  // clear canvas
  context.clearRect(0,0,640,480);
  // draw sprite
  context.save();
  context.translate(x,y);
  context.drawImage(sprite,-8,-8);
  context.restore();
}

function simple() {
  // simple (a)synchronous request
  var request = new XMLHttpRequest();
  if (!request)
    return;
  request.open("POST", 'simple.php', false);
  request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  request.send(null);
  if (request.status == 200) {
    var s = request.responseText.split(' ');
    x = 1*s[0];
    y = 1*s[1];
    //document.title = 'x='+x+' y='+y;
  } else
    document.title = 'simple: '+request.responseText;
}

